package com.laolu.icon.utils;

import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

@Slf4j
public class MyFileRead implements AutoCloseable {
	
	private final BufferedReader reader;
	
	public MyFileRead(String filePath) throws Exception {
		this.reader = new BufferedReader(new FileReader(filePath));
	}
	
	public <T> List<T> readList(Class<T> clazz) throws IOException {
		String s;
		List<T> list = new LinkedList<>();
		while ((s = reader.readLine()) != null) {
			T o = JSONObject.parseObject(s, clazz);
			list.add(o);
//			log.info("{}", o);
		}
		return list;
	}
	
	@Override
	public void close() throws Exception {
		reader.close();
	}
}
